package com.cman777.springc.ratelimiter.interceptor;

import com.cman777.springc.ratelimiter.RateLimiterClient;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author chenzhicong
 * @time 2020/9/18 16:36
 */
public class ServletInterceptor  implements HandlerInterceptor {

    private RateLimiterClient rateLimiterClient;

    public ServletInterceptor(RateLimiterClient rateLimiterClient){
        this.rateLimiterClient = rateLimiterClient;
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
        return !rateLimiterClient.handle4Servlet(request);
    }
}
